import api from './index';

/**
 * 分页获取商品列表
 */
export const getGoodsList = (params: PageParams): Promise<ResponseData<GoodsList>> => {
  return api.post('/shop/getAll', params);
};

/**
 * 获取购物车列表
 */
export const getCartListApi = (params: PageParams): Promise<ResponseData<PageList<CartList>>> => {
  return api.post('/shop/cart', params);
};

/**
 * 添加商品到购物车
 */
export const addGoods = (params: AddGoodsParams): Promise<ResponseData<null>> => {
  return api.post('/shop/cart/add', params);
};

/**
 * 删除购物车商品
 */
export const deleteGoods = (params: number[]): Promise<ResponseData<null>> => {
  return api.post('/shop/cart/delete', params);
};

/**
 * 根据id更新单个购物车数据
 */
export const updateGoods = (id: number, params: AddGoodsParams): Promise<ResponseData<null>> => {
  return api.post('/shop/cart/update/' + id, params);
};


/**
 * 新增商品
 */
export const addShopGoods = (params: Omit<ShopGoods, 'id' | 'created_time'>): Promise<ResponseData<null>> => {
  return api.post('/shop/create', params);
};

/**
 * 删除商品
 */
export const deleteShopGoods = (id: number): Promise<ResponseData<null>> => {
  return api.get('/shop/delete/' + id);
};

/**
 * 更新商品
 */
export const updateShopGoods = (params: ShopGoods): Promise<ResponseData<null>> => {
  return api.post('/shop/update', params);
};

/**
 * 上传图片
 */
export const uploadImage = (params: FormData): Promise<ResponseData<string>> => {
  return api.post('/upload/imgFile', params);
};

